<?php

namespace DebugComponent\Plugin;

class File implements \DebugComponent\IMessagePlugin, \DebugComponent\IRenderable {

    public function  __construct() {
        $this->files = array();
    }

    public function setRenderer(\DebugComponent\IRenderer $renderer) {
        $this->renderer = $renderer;
    }

    public function getListenMessages() {
        return array('\DebugComponent\Message\File');
    }

    public function write(\DebugComponent\IMessage $message) {
        $this->files[] = $message;
    }

    public function getTitle() {
        return 'Files';
    }

    public function getSubtitle() {
        return count($this->files);
    }

    public function render() {
        $data = new \DebugComponent\ParameterHolder();
        $data->set('files', $this->files);
        $data->set('includedFiles', \get_included_files());
        $data->set('title', $this->getTitle());
        $data->set('subtitle', $this->getSubtitle());
        return $this->renderer->render($data);
    }

    private $files;
    private $renderer;
}